<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="css/table.css" rel="stylesheet" type="text/css" />
<link href="css/excite-bike/jquery-ui-1.8.22.custom.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.MultiFile.pack.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/jquery-ui-1.8.22.custom.min.js"></script>
<script src="js/widgets.js"></script>


<script type="text/javascript">
$(document).ready(function() {
	
	$("#dialog-TRlevel_01").css("visibility", "hidden");
	$("#dialog-infoMR").css("visibility", "hidden");
	$("#loginUser")[0].value = $.cookie("userID");	
	$("#sub_submittedBy")[0].value = "reviewer";	//為了使同一支程式，能交分辨提交人員的角色
	
	/** 趁一開始，將測試結果的種類抓回來 **/
	$.ajax({
		type : "post",
		url : "GetTRresultType",
		dataType : "JSON",
		success : function(TRType) {
			$.each(TRType.sqlData, function(i, res) {
				trType.push(res);
			});
		},error : function(xhr, ajaxOptions, thrownError) {
			alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
		}
	});
	
	
	$.ajax({														
		type : "post",
		data : $("#q_form").serializeArray(),
		url : "ReviewTR",
		dataType : "json",
		success : function(queryResult) {
			var i=999;
			var m=0;
			if (queryResult.size > 0) {
				$.each(queryResult.sqlData, function(a, res) {
					var isReviewer = res.isReviewer;
					var tpid = res.tpid;
					var mrid = res.mrid;
					var ver = res.ver;
					var sourceid = res.sourceid;
					var mrdescription = res.mrdescription;
					
					
					var tester = "";
					if (res.tester != undefined) {
						$.each(res.tester,function(indexTester,user) {
							tester += "<li class=\"mrTestOwner\" nickName=\""+user.nickName+"\" val=\""+user.userID+"\">"+user.nickName+"</li>";
						});	
					}
					
					var ind = $("#mainTbody tr").length+1;
					var bgcolor=getbgColor(ind);
					
					var butText = "處理";
					
					if (!isReviewer) {
						butText ="檢視";
						$(".onlyForReviewer").remove();
					}
					
					$("#mainTbody").append("<tr id=\""+mrid+"\" sel=\""+i+"\" cont=\""+m+"\" isInDB=\"false\" class=\"inTmp\" ondblclick=\"trDoubleClick('"+i+"','"+m+"','"+mrid+"')\" bgcolor="+bgcolor+"><td>"+ind+"</td><td><input type=\"text\" size=\"21\" sel=\""+i+"\" cont=\""+m+"\" value=\""+sourceid+"\" attr=\"sourceid\" mrid=\""+mrid+"\" /></td><td><textarea id='"+mrid+"_mrDesc' sel=\""+i+"\" cont=\""+m+"\" attr=\"mrdescription\" mrid=\""+mrid+"\" onchange=\"updateMRItem(this)\" >"+mrdescription+"</textarea></td><td><ul id=\""+mrid+"_mrTester\" >"+tester+"</ul></td><td>"+df(1)+"</td><td id=\"lupt_"+mrid+"\">"+df(1)+"</td><td><button id='"+mrid+"_reviewTR' mrid=\""+mrid+"\" ver=\""+ver+"\" tpid=\""+tpid+"\" isReviewer=\""+isReviewer+"\" class='reviewTC' onClick=\"Click_reviewTR(this)\" type=\"button\">"+butText+"</button><button id='"+mrid+"_infoItem' mrid=\""+mrid+"\" ver=\""+ver+"\" tpid=\""+tpid+"\" tpname=\""+res.tpName+"\"  class='infoItem' onClick=\"Click_infoItem(this)\" type=\"button\">相關資訊</button></td></tr>");
				});
			}
		}
	});
	
});
	
	var trType = [];	//測試結果類型
	
function reviewTR(isAccepted) {
	$("#sub_isAccepted")[0].value = isAccepted;
	$("#sub_submitorComment")[0].value = $("#submitorComment").val();
	
	$.ajax({
		type : "post",
		url : "ReviewTR_ACT",
		data : $("#q_form").serializeArray(),
		dataType : "TEXT",
		success : function(res) {
			if (res =="OK") {
				alert("完成回覆");
			} else {
				alert("回覆失敗");
			}
		}
	});
}
	
function napoleon() {
	$("#TRlevel_01_body tr").remove();
	$.ajax({
		type : "post",
		url : "GetTRlevel_01_body",
		data : $("#q_form").serializeArray(),
		dataType : "JSON",
		success : function(Result) {
			var tcuid =[];
			var size = Result.size;
			var comment="Noc"
			$.each(Result.sqlData, function(i, res) {
				var ver = res.ver;
				var ind= i+1;
				var bgcolor=getbgColor(ind);
				var trSN = res.trSN;
				var tr = "";
				comment = res.comment;
				if (trSN != 0) {
					for(o=0;o<trType.length;o++) {
						if (trType[o].sn == trSN) {
							tr = trType[o].name+ " (" + trType[o].value + ")";
						}
					}
				} else {
					tr ="";
				}
				
				$("#TRlevel_01_body").append("<tr ondblclick=\"caesar('"+res.tcuid+"')\" bgcolor=\""+bgcolor+"\"><td class=\"center\">"+ind+"</td><td>"+res.tcName+"</td><td>"+res.tcKeyPoint+"</td><td>"+res.tcResExp+"</td><td id=\""+res.tcuid+"_level01_tr\">"+tr+"</td><td class=\"right\"  id=\""+res.tcuid+"_level01_retenum\" >"+(res.retenum==0?"":res.retenum)+"</td><td class=\"right\">"+res.numKeyPoint+"</td><td id=\""+res.tcuid+"_level01_succnum\" class=\"right\">"+(res.succnum==0?"":res.succnum)+"</td><td id=\""+res.tcuid+"_level01_failnum\" class=\"right\">"+(res.failnum==0?"":res.failnum)+"</td><td id=\""+res.tcuid+"_level01_cantnum\" class=\"right\">"+(res.cantnum==0?"":res.cantnum)+"</td><td id=\""+res.tcuid+"_level01_waitnum\" class=\"right\">"+(res.waitnum==0?"":res.waitnum)+"</td></tr>");
				
				if (tr == "") {
					$("#"+res.tcuid+"_level01_tr").html("未測試 (unattempted)");
				}
				$("#"+res.tcuid+"_level01_tr").attr("tok",trSN);
				
			});
			if (comment != "Noc") {
				$("#testerComment").val(comment);
			}
			
			$("#dialog-TRlevel_01").css("visibility", "visible");
		}, error : function(xhr, ajaxOptions, thrownError) {
			alert("出代誌啊!! \n\n"+xhr.status+"\n\n"+xhr.responseText);
		}
	});
}


function Click_reviewTR(obj) {
	var mrid = $(obj).attr("mrid");
	$("#sub_mrid")[0].value = mrid;
	var tpid = $(obj).attr("tpid");
	$("#sub_tpid")[0].value = tpid;
	var mrdescription = $("#"+mrid+"_mrDesc").val(); 
	$("#TRlecel_01_mrDesc").html(mrdescription);
	var ver = $(obj).attr("ver");
	$("#sub_ver")[0].value = ver;
	$("#loginUser")[0].value = $.cookie("userID");
	var isReviewer = $(obj).attr("isReviewer");
	napoleon();
	
	if (isReviewer=="true") {
		$("#dialog-TRlevel_01").dialog({
			resizable : true,
			width : 1100,
			height : 600,
			modal : true,
			buttons : {
				"同意" : function() {
					/** 將TextArea的實體刪除，否則後面再點開時會錯 **/
				 	var mrid = $("#sub_mrid")[0].value;
					$("#"+mrid+"_reviewTR").attr("disabled","disabled");
					reviewTR(1); 
					$(this).dialog("close");
				},"拒絕" : function() {
					 var mrid = $("#sub_mrid")[0].value;
					$("#"+mrid+"_reviewTR").attr("disabled","disabled");
					reviewTR(0); 
					$(this).dialog("close");
				},"關閉" : function() {
					$(this).dialog("close");
				}
			}
		});	
	} else {
		$("#dialog-TRlevel_01").dialog({
			resizable : true,
			width : 1100,
			height : 600,
			modal : true,
			buttons : {
				"關閉" : function() {
					$(this).dialog("close");
				}
			}
		});	
	}
	
	$("#dialog:ui-dialog").dialog("destroy");
}

</script>
</head>
<body>
<div id="tpBody">
	<table>
		<thead>
			<tr>
				<th>#</th>
				<th width="230">項目編號</th>
				<th><font face="標準體" color="#FF0000"><sub>*</sub></font>項目名稱</th>
				<th>測試負責人</th>
				<th>建立日期</th>
				<th>最後修改日期</th>
				<th>&nbsp;</th>
			</tr>
		</thead>
		
		<tbody id="mainTbody">
		</tbody>
	</table>
	</div>
	
	<form id="q_form" method="post">
		<input type="hidden" id="sub_tpid" name="tpid" />					<!-- 測試案ID -->
		<input type="hidden" id="sub_mrid" name="mrid" />					<!-- 測試項目ID -->
		<input type="hidden" id="sub_submittedBy" name="submittedBy" />		<!-- 送出的角色為 -->
		<input type="hidden" id="sub_isAccepted" name="isAccepted" />		<!-- 同意還是拒絕 -->
		<input type="hidden" id="sub_ver" name="ver" />						<!-- 目前測試項目選擇案例的版次 -->
		<input type="hidden" id="loginUser" name="loginUser" />				<!-- 目前登入的使用者 -->
		<input type="hidden" id="sub_submitorComment" name="submitorComment" />				<!-- 送審者的意見 -->
	</form>
	
	<div id="dialog-TRlevel_01">
	<table>
		<thead>
			<tr><th class="query" width="13%" >測試項目：</th><td id="TRlecel_01_mrDesc" colspan="11"></td></tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
			<tr>
				<th class="center">#</th>
				<th class="center">測試案例<br/>名稱</th>
				<th class="center">驗證重點</th>
				<th class="center">預期結果</th>
				<th class="center">測試結果</th>
				<th class="center">重驗<br/>次數</th>
				<th class="center">驗證<br/>重點數</th>
				<th class="center">成功數</th>
				<th class="center">失敗數</th>
				<th class="center">無法測試數</th>
				<th class="center">待測數</th>
			</tr>
		</thead>
		<tbody id="TRlevel_01_body">
			
		</tbody>
		<tfoot>
			<tr><th class="left" colspan="2">送審人員意見</th><td rowspan="2" colspan="2"></td></tr>
			<tr><td colspan="2"><textarea id="testerComment" cols="60" DISABLED></textarea></td><td></td></tr>
			
			<tr class="onlyForReviewer"><th class="left" colspan="2">意見</th><td rowspan="2" colspan="2"></td></tr>
			<tr class="onlyForReviewer"></tr>
			<tr class="onlyForReviewer"><td colspan="2"><textarea id="submitorComment" cols="60"></textarea></td><td></td></tr>
		</tfoot>
	</table>
	</div>
	
	<div id="dialog-infoMR" title="相關資訊">
		<p>
		<table>
		<tr><th width="50%">上傳附加檔案</th><th width="50%">簽核意見</th></tr>
		<tr><td>
			<form id="form_infoFileUpload" method="post" enctype="multipart/form-data" target="FileUpload" action="FileUpload">
				<input name="file" id="file2" size="27" type="file" class="multi" />
				<input type="hidden" id="infoLoginUserFileUpload" name="loginUser" />					<!-- 目前登入的使用者 -->
				<input type="hidden" id="infoTpidFileUpload" name="tpid" />						<!-- 測試案ID -->
				<input type="hidden" id="infoMridFileUpload" name="mrid" />						<!-- 測試項目ID -->
				<iframe id="FileUpload" name="FileUpload" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
			</form>
			<br/>
		<button onClick="Click_infoFileUpload()" type="button">上傳檔案</button>
		</td>
		<td>
		<form id="form_infoComment" method="post">
			<textarea id="textarea_infoComment"></textarea>
		</form>
		<br/><button onClick="Click_infoComment()" type="button">送出意見</button>
		
		</td>
		</tr>
		</table>
		
		<p>
		<p>
		<table width="100%">
			<tr><th class="query">計畫案</th><td colspan="5" id="info_tpName">&nbsp;</td></tr>
			<tr><th class="query">測試項目</th><td colspan="5" id="info_mrDesc">&nbsp;</td></tr>
			<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
			<tr><th class="query">指派人員</th><td class="query" id="info_assignedTester"><ul id="mrTester"></ul></td></tr>
			<tr>
				<th class="query">指定案例</th><td id="info_assignedTC"><ul id="mrTC"></ul></td>
				<th class="query">送審案例</th><td id="info_subTC">&nbsp;</td>
				<th class="query">測試案例審核</th><td id="info_reviewTC">&nbsp;</td>
			</tr>
			<tr> 
				<th class="query">結果更新</th><td id="info_fillTR">&nbsp;</td>
				<th class="query">送審結果</th><td id="info_subTR">&nbsp;</td>
				<th class="query">測試結果審核</th><td id="info_reviewTR">&nbsp;</td>
			</tr>
		</table>
	
		<div id="infoAction"></div>
		<div id="infoComment"></div>
		<div id="infoFileUpload"></div>
	</div>
	<form id="form_fileDoload" method="post" target="FileDownload" action="FileDownload">
		<input type="hidden" id="sub_sn" name="sn" />			
		<iframe id="FileDownload" name="FileDownload" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
	</form>
	<input type="hidden" id="hidden_testPlanName"/>
</body>
</html>